#include "person.pb.h"
#include <iostream>
#include <stdio.h>
#include <time.h> 
#include <sys/time.h> 

using namespace test;

int main(int argc, char* argv[])
{
    GOOGLE_PROTOBUF_VERIFY_VERSION;
	Person person;
	person.set_id(1000);
	person.set_name("Alice");
	person.set_email("Alice@example.com");
	/*
	Phone* pPhone1 = person.AddExtension(Phone::phones);
	pPhone1->set_num("2147483647");
	pPhone1->set_type(Phone_PHONE_TYPE_HOME);
	Phone* pPhone2 = person.AddExtension(Phone::phones);
	pPhone2->set_num("123456789");
	pPhone2->set_type(Phone_PHONE_TYPE_MOBILE);
	
	//int aaa = person.ExtensionSize(Phone::phones);
	//Phone pPhone3 = person.GetExtension(Phone::phones, 1);
	*/
	
	Person personShow;
	struct timeval t_start,t_end; 
    gettimeofday(&t_start, NULL); 
    long start = ((long)t_start.tv_sec)*1000+(long)t_start.tv_usec/1000;
    std::string data; 
    for(int i=0; i< 100000; i++)
	{
		person.SerializeToString(&data);
		personShow.ParseFromString(data);
	}
	printf("%s\n", personShow.DebugString().data());
    gettimeofday(&t_end, NULL); 
    long end = ((long)t_end.tv_sec)*1000+(long)t_end.tv_usec/1000; 

    long cost_time = end - start; 
    printf("cost_time: %ld ms\n", cost_time); 

    google::protobuf::ShutdownProtobufLibrary();
	return 0;
}
